package com.weipt.security;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //此处我们需要根据方法入参username，从数据库查询账号信息，这里我们直接写死
        UserDetailsDto userDetailsDto = new UserDetailsDto();
        userDetailsDto.setUsername("weipt");
        userDetailsDto.setPassword(new BCryptPasswordEncoder().encode("123"));  //正常情况下，数据库存储的已经是密文，此处就不用再加密
        return userDetailsDto;
    }
}
